package com.test.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.test.entity.dto.Account;
import com.test.entity.dto.AccountDetails;
import com.test.entity.vo.request.SaveAccountVo;
import com.test.mapper.AccountDetailsMapper;
import com.test.service.AccountDetailsService;
import com.test.service.AccountService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class AccountDetailsServiceImpl extends ServiceImpl<AccountDetailsMapper,AccountDetails> implements AccountDetailsService {

    @Resource
    AccountService accountService;
    @Override
    public AccountDetails findByAccountId(int id) {
        return this.getById(id);
    }

    @Override
    public Boolean save(int id, SaveAccountVo vo) {
        Account account = accountService.findByUsername(vo.getUsername());
        if (account == null || account.getId() == id){
                accountService.update()
                        .eq("id",id)
                        .set("username",vo.getUsername())
                        .update();
                this.saveOrUpdate(new AccountDetails(id,vo.getGender(),vo.getQq(),vo.getVx(),vo.getPhone(),vo.getDes()));
                return true;
        }
        return false;

    }
}
